package com.szeldon.pj.jps.qres;

import java.util.logging.Logger;

public class IntegerResult extends AbstractQueryResult {
	private static final Logger logger = Logger.getLogger(IntegerResult.class.getName());

	private int integer;

	/**
	 * 
	 * @param integer
	 */
	public IntegerResult(int integer) {
		this.integer = integer;
	}

	public int getInteger() {
		return integer;
	}

	@Override
	public String toString() {
		return "integer(" + integer + ")";
	}

	@Override
	public int compareTo(AbstractQueryResult result) {
		if (result instanceof IntegerResult || result instanceof RealResult) {
			double resultDouble = 0;
			if (result instanceof IntegerResult) {
				resultDouble = ((IntegerResult) result).getInteger();
			} else {
				resultDouble = ((RealResult) result).getReal();
			}
			if (integer < resultDouble) {
				return -1;
			} else if (integer == resultDouble) {
				return 0;
			} else {
				return 1;
			}

		} else {
			throw new IllegalStateException("Integer result can't be compared with " + result.getClass().getName()
					+ " result.");
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj.getClass().equals(this.getClass())) {
			IntegerResult objResult = (IntegerResult) obj;
			if (integer == objResult.getInteger()) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (""+integer).hashCode();
	}
	
	

}
